Ext.ux.ModifyCorpration = Ext.extend(Ext.Window, {
	initComponent : function(config) {
		var basePath = document.getElementById('basePath').href;
		var linedata = Ext.getCmp("corprationDataGrid").getStore()
				.getAt(Ext.getCmp("corprationDataGrid").getSelectionModel().lastActive);
		var lang;
		
		var modifyForm = new Ext.FormPanel({
        	labelWidth : 100, // label settings here cascade unless overridden
			url : basePath + 'corpration/update.action',
			autoScroll:true,
			frame : true,
			region : 'center',
			border:true,
			fileUpload: true,
			bodyStyle : 'padding:5px 5px 0',
			width : '100%',
			defaults : {
				width : 220
			},
			defaultType : 'textfield',

			items : [{
				fieldLabel : '语言',
				xtype:'displaytext',
				id:'corprationLangUpdate',
				editable:false,
				allowBlank : false
			},{
				fieldLabel : '企业地址',
				name : 'corpration.address',
				id:'corprationAddressUpdate',
				allowBlank : false
			},{
				fieldLabel : '企业邮箱',
				name : 'corpration.email',
				vtype:"email",//email格式验证
                vtypeText:"不是有效的邮箱地址",//错误提示信息,默认值我就不说了
				id:'corprationEmailUpdate',
				allowBlank : false
			},{
				fieldLabel : '企业传真',
				name : 'corpration.fax',
				id:'corprationFaxUpdate',
				allowBlank : false
			},{
				fieldLabel : '联系电话',
				name : 'corpration.telephone',
				id:'corprationTelephoneUpdate',
				allowBlank : false
			},{
				fieldLabel : '所在地邮编',
				name : 'corpration.zipcode',
				id:'corprationZipcodeUpdate',
				allowBlank : false
			},{
				xtype:'StarHtmleditor',
				fieldLabel : '企业简介',
				anchor:'95%',
				height:300,
				allowBlank : false,
				autoScroll:true,
				url:basePath + 'base/upload.action',
				id:'corprationAboutUsUpdate',
				name : 'corpration.aboutUs'
			},{
				xtype:'StarHtmleditor',
				fieldLabel : '企业文化',
				anchor:'95%',
				height:300,
				allowBlank : false,
				autoScroll:true,
				url:basePath + 'base/upload.action',
				id:'corprationCultureUpdate',
				name : 'corpration.culture'
			},{
				xtype:'StarHtmleditor',
				fieldLabel : '企业前景',
				anchor:'95%',
				height:300,
				allowBlank : false,
				autoScroll:true,
				url:basePath + 'base/upload.action',
				id:'corprationProspectsUpdate',
				name : 'corpration.prospects'
			}],
			bbar : ['->', {
				text : '保存',
				handler:function() {
					if(!modifyForm.form.isValid())return;
					modifyForm.form.submit( {
						waitMsg : '正在修改......',
						url : basePath + 'corpration/update.action?corpration.id=' + linedata.json.id + 
								'&corpration.lang=' + linedata.json.lang,
						method : "POST",
						success : function(form, action) {
							form.reset();
							Ext.getCmp('modifyCorprationWin').close();
							Ext.MessageBox.alert('提示', '更新成功');
							Ext.StoreMgr.get('corprationStore').reload();
						},
						failure : function(form, action) {
							if (action.failureType == Ext.form.Action.SERVER_INVALID)
								Ext.MessageBox.alert('警告', action.result.msg);
						}
					});
				}
			}, {
				xtype:'spacer',
				width:50
			}]
		});
		
		Ext.Ajax.request( {
			url : basePath + 'corpration/load.action?corpration.id=' + linedata.json.id,
			method : 'post',
			callback : function(op, success, response) {
				var jsonObject = eval('(' + response.responseText + ')');
				lang = jsonObject.lang;
				Ext.getCmp("corprationAddressUpdate").setValue(jsonObject.address);
    			Ext.getCmp("corprationEmailUpdate").setValue(jsonObject.email);
    			Ext.getCmp("corprationFaxUpdate").setValue(jsonObject.fax);
    			Ext.getCmp("corprationTelephoneUpdate").setValue(jsonObject.telephone);
				Ext.getCmp("corprationZipcodeUpdate").setValue(jsonObject.zipcode);
    			Ext.getCmp("corprationAboutUsUpdate").setValue(jsonObject.aboutUs);
    			Ext.getCmp("corprationCultureUpdate").setValue(jsonObject.culture);
    			Ext.getCmp("corprationProspectsUpdate").setValue(jsonObject.prospects);
    			var langName;
    			switch(jsonObject.lang) {
    				case 'zh_CN' : langName = '简体中文'; break;
    				case 'zh_TW' : langName = '繁体中文'; break;
    				case 'en_US' : langName = '美式英文'; break;
    			}
    			Ext.getCmp("corprationLangUpdate").setValue(langName);
			}
		});
		
		Ext.apply(this, {
			title: "修改企业信息",
	        plain: true,
	        width:1000,
	        height:600,
	        modal: true,
	        maximizable:true,
	        border: false,
	        layout: 'border',
	        autoScroll:true,
	        items: [modifyForm]
		});
		Ext.ux.ModifyCorpration.superclass.initComponent.apply(this, arguments);
	}
});
Ext.reg('lgnModifyCorpration', Ext.ux.ModifyCorpration);
